// *************** ep1 ******************
// function someworklet(greeting) {
//   'worklet'
//   console.log('someworklet', greeting)
// }
// someworklet('hello')

// wx.worklet.runOnUI(someworklet)('hello')

// *************** ep2 ******************
// const name = 'skyline'
// function anotherWorklet() {
//   'worklet'
//   return 'hello' + name
// }

// function someWorklet() {
//   'worklet'
//   const greeting = anotherWorklet()
//   console.log('another worklet says ', greeting)
// }

// wx.worklet.runOnUI(someWorklet)()

// *************** ep3 ******************
// function someFunc(greeting) {
//   console.log('hello', greeting)
// }

// function someWorklet() {
//   'worklet'
//   wx.worklet.runOnJS(someFunc)('skyline')
// }
// wx.worklet.runOnUI(someWorklet)()

// *************** ep4 ******************
// const { shared, runOnUI } = wx.worklet
// const offset = shared(0)
// function someWorklet() {
//   'worklet'
//   console.log(offset.value)
//   offset.value = 2
//   console.log(offset.value)
// }
// // offset.value = 1
// runOnUI(someWorklet)()
// setTimeout(() => {
//   console.log(offset.value)
// }, 0)
const { timing, shared, Easing, runOnJS } = wx.worklet

Page({
  data: {
    msg: 'Skyline',
  },
  onLoad(options) {
    // const offset = shared(0)
    // this.applyAnimatedStyle('#moved-box', () => {
    //   'worklet'
    //   return {
    //     transform: `translateX(${offset.value}px)`,
    //   }
    // })
    // this._offset = offset
    // const toValue = 100
    // const showModal = this.showModal.bind(this)
    // timing(toValue, { duration: 300 }, () => {
    //   'worklet'
    //   runOnJS(showModal)(msg)
    // })
  },
  handleTap() {
    'worklet'
    const msg = this.data.msg
    console.log('handleTap', msg)
    const showModal = this.showModal.bind(this)
    // runOnJS(showModal)(msg)

    const toValue = 100
    timing(toValue, { duration: 300 }, () => {
      'worklet'
      console.log(111)
      runOnJS(showModal)(msg)
    })
    this.doSomething()
  },

  doSomething() {
    'worklet'
    console.log('doSomething')
  },

  // tap() {
  //   console.log('tap')
  //   // console.log(Math.random())
  //   this._offset.value = timing(300, {
  //     duration: 200,
  //     easing: Easing.ease,
  //   })
  // },
  // handlPan(evt) {
  //   'worklet'
  //   console.log(evt)
  //   if (evt.state === 2) {
  //     this._offset.value += evt.deltaX
  //   }
  // },
  showModal(msg) {
    wx.showModal({
      title: msg,
    })
  },
})
